package com.itheima.ydd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.ydd.dto.Advposnums;
import com.itheima.ydd.entity.Advimg;
import com.itheima.ydd.entity.Advpos;
import com.itheima.ydd.mapper.AdvimgMapper;
import com.itheima.ydd.service.AdvimgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class AdvimgServiceImpl extends ServiceImpl<AdvimgMapper, Advimg> implements AdvimgService {
    @Autowired
    private AdvimgMapper advimgMapper;

    @Override
    public HashMap<String, Object> getPageHashMap(String advimgdesc, String advimgpos, Integer page, Integer limit) {
        Page<Advimg> advimgPage = new Page<>(page, limit);
        LambdaQueryWrapper<Advimg> lqw = new LambdaQueryWrapper<>();
        lqw.like(advimgdesc != null, Advimg::getAdvimgdesc, advimgdesc)
                .like(advimgpos != null, Advimg::getAdvimgpos, advimgpos);
        this.page(advimgPage, lqw);
        List<Advimg> records = advimgPage.getRecords();
        Integer count = this.count(lqw);
        HashMap<String, Object> map = new HashMap<>();
        map.put("count", count);
        map.put("currentPage", page);
        map.put("pageSize", limit);
        map.put("totalPages", advimgPage.getTotal());
        map.put("data", records);
        return map;
    }

    @Override
    public List<Advposnums> getAdvposnums() {
        return advimgMapper.getAdvposnums();
    }
}
